package com.bzkj.basicinfo.service.basic.impl;

import com.bzkj.basicinfo.domain.basic.BasicPicInfo;
import com.bzkj.basicinfo.mapper.BasicPicInfoMapper;
import com.bzkj.basicinfo.service.basic.BasicPicInfoService;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class BasicPicInfoServiceImpl implements BasicPicInfoService {

    @Autowired
    private BasicPicInfoMapper basicPicInfoMapper;

    @Override
    public List<BasicPicInfo> findBasicPicInfoList(BasicPicInfo entity) {
        return basicPicInfoMapper.findBasicPicInfoList(entity);
    }

    @Override
    public AjaxResult basicPicInfoSave(BasicPicInfo entity) {
        String userName = SecurityUtils.getLoginUser().getUser().getUserName();
        entity.setCreator(userName);
        entity.setCreateTime(new Date());
        try {
            basicPicInfoMapper.basicPicInfoSave(entity);
            return AjaxResult.success("新增成功");
        } catch(Exception e) {
            log.error("修改失败:{}", e);
            return AjaxResult.error("新增失败");
        }
    }

    @Override
    public AjaxResult basicPicInfoUpdate(BasicPicInfo entity) {
        try {
            basicPicInfoMapper.basicPicInfoUpdate(entity);
            return AjaxResult.success("修改成功");
        } catch(Exception e) {
            log.error("修改失败:{}", e);
            return AjaxResult.error("修改失败");
        }
    }

    @Override
    public AjaxResult deleteBasicPicInfoById(String id) {
        int i = basicPicInfoMapper.deleteById(id);
        if(i > 0){
            return AjaxResult.success("删除成功");
        }else{
            return AjaxResult.error("删除失败");
        }
    }
}
